#ifndef __PROGRESS_BAR_H
#define __PROGRESS_BAR_H

#define MOVERIGHT(y)    (printf("\033[%dC",(y)))
#define MOVEDOWN(x)     (printf("\033[%dB", (x)))
#define MOVEUP(x)       (printf("\033[%dA", (x)))
#define MOVELEFT(y)     (printf("\033[%dD", (y)))
#define MOVETO(x,y) 	(printf("\033[%d;%dH",(x),(y)))
#define HIDE_CURSOR()   (printf("\033[?25l"))
#define SHOW_CURSOR()   (printf("\033[?25h"))
#define NONE            ("\033[0m")
#define BACK_COLOR      ("\033[%dm")

#define INIT_X_DIRECTION        (1)
#define INIT_Y_DIRECTION        (1)
#define INIT_OUTSIDE_COLOR      (40)
#define INIT_INSIDE_COLOR       (47)
#define INIT_SPEED              (10000)
#define INIT_LENGTH             (100)
#define MIN_DIRECTION           (1)
#define MAX_DIRECTION           (40)                
#define MAX_COLOR               (47)
#define MIN_COLOR               (40)
#define MIN_SPEED               (0) 
#define MAX_SPEED               (200000)
#define MIN_LENGTH              (0)
#define MAX_LENGTH              (150)

#define TURE                    (0)
#define FAULT                   (-1)

#define MIN_FUNC                (0)
#define MAX_FUNC                (2)
#define INSIDE                  (1)
#define OUTSIDE                 (0)

struct progress_bar {
    /* 速度 */
    int speed;
    /* 外框颜色 */
    int outside_color;
    /* 进度条颜色 */  
    int inside_color;
    /* 进度条长度 */     
    int length;
    /* 以左上角为原点，向右平移的距离 */         
    int x_direction; 
    /* 以左上角为原点，向下平移的距离 */   
    int y_direction;       
};

typedef void (*func_t)(int, int, int, int, int);

extern int progress_bar_init(struct progress_bar *progress_bar, func_t *draw);
extern int progress_bar_run(struct progress_bar *progress_bar, func_t *draw);
extern void progress_bar_destroy(void);
extern void set_terminal_param(int param_argc, char *param_argv[], struct progress_bar *progress_param);
extern void printf_outside(int length, int outside_color, int speed, int x_direction, int y_direction);
extern void printf_inside(int length, int inside_color, int speed, int x_direction, int y_direction);

#endif
